<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 10px;
          text-align: center;
            margin: 10px auto;
        }
    </style>
</head>
<body>
    <div>
         <button id="btn">0</button>
    </div>
   
   <script>
       window.onload = function(){
           var btn = document.getElementById('btn')
           var i =0
           btn.onclick = function(){
               btn.innerText = ++i
               alert(i)
           }
       }
   </script>
</body>
</html>